﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using LitJson;
using Photon.SocketServer;
using TaiDouCommon;
using TaiDouCommon.Model;
using TaiDouPhotonServer;
using TaiDouPhotonServer.DB.Manager;

namespace TaiDouPhotonServer.Handlers
{
    //服务器列表协议
    class ServerHandler:HandlerBase
    {
        private ServerPropertyManager manager;

        public ServerHandler()
        {
            manager = new ServerPropertyManager();
        }
        public override OperationCode OpCode
        {
            get
            {
                return OperationCode.GetServerList;
            }
        }
        public override OperationResponse OnHandleMessage(OperationRequest request, ClientPeer peer)
        {
            OperationResponse response = new OperationResponse(request.OperationCode);

            //服务器列表
            List<ServerProperty> list = manager.GetServerList();
            Dictionary<byte, object> parameters = new Dictionary<byte, object>();
            //json转换
            string json = JsonMapper.ToJson(list);
            parameters.Add((byte)ParameterCode.ServerList, json);

            //设置返回码标记
            response.ReturnCode = (short)ReturnCode.Succ;
            response.Parameters = parameters;


            return response;
        }
    }
}
